package edu.ifce.fisica1.persistence;

import java.util.List;
import java.util.ResourceBundle;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

import edu.ifce.fisica1.bean.Materia;

public enum DAO {
	DAO;

	private static final PersistenceManagerFactory pmfInstance = JDOHelper
			.getPersistenceManagerFactory("burndown-pmf");
	private ResourceBundle b = ResourceBundle//
			.getBundle("edu.ifce.fisica1.persistence.DAO");

	public void salvar(Materia m) {
		PersistenceManager pm = pmfInstance.getPersistenceManager();
		try {
			pm.makePersistent(m);
		} finally {
			pm.close();
		}
	}

	@SuppressWarnings("unchecked")
	public List<Materia> listar() {
		PersistenceManager pm = pmfInstance.getPersistenceManager();
		Object l = pm.newQuery(b.getString("select-materia")).execute();
		return (List<Materia>) l;
	}
}
